package com.xpgk.mvc.right;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.jfinal.aop.Before;
import com.jfinal.log.Log;
import com.xpgk.dto.RenderBean;
import com.xpgk.dto.ZtreeNode;
import com.xpgk.mvc.base.BaseController;
import com.xpgk.mvc.dept.DeptValidator;

/**
 * 模块管理
 *
 */
public class RightController extends BaseController {

	@SuppressWarnings("unused")
	private static final Log log = Log.getLog(RightController.class);

	private RightService rightService;

	private String pIds; // 上级节点ds
	private String name; // 节点名称
	private int orderId; // 排序号
	private int level;// 级别
	private String privilegess;// 是否验证

	public void index() {
		render("right.html");
	}

	/**
	 * tree节点数据
	 */
	public void treeData() {
		Map<String, Object> queryParam = new HashMap<String, Object>();
		queryParam.put(Right.column_ids, ids);
		queryParam.put(Right.column_parentids, pIds);
		queryParam.put(Right.column_name, name);
		queryParam.put(Right.column_orderid, orderId);
		queryParam.put(Right.column_level, level);
		queryParam.put(Right.column_privilegess, privilegess);
		List<ZtreeNode> nodeList = rightService.childNodeData(getCxt(), queryParam);
		renderJson(nodeList);
	}

	/**
	 * 跳转至添加
	 */
	public void toAdd() {
		render("addRight.html");
	}

	/**
	 * 添加模块
	 */
	@Before(RightValidator.class)
	public void addRight() {
		Right right = getModel(Right.class);
		RenderBean renderBean = rightService.addRight(right);
		renderJson(renderBean);
	}

	/**
	 * 跳转至更新
	 */
	public void toUpdate() {
		setAttr("right", Right.dao.findById(ids));
		render("updateRight.html");
	}

	/**
	 * 更新
	 */
	@Before(RightValidator.class)
	public void updateRight() {
		Right right = getModel(Right.class);
		RenderBean renderBean = rightService.update(right);
		renderJson(renderBean);
	}

	/**
	 * 删除
	 */
	public void deleteRight() {
		String result = rightService.delete(ids);
		renderText(result);
	}

	/**
	 * 功能列表
	 */
	public void rightList() {
		String json = paging(splitPage, Right.sqlId_splitPageSelect, Right.sqlId_splitPageFrom);
		renderJson(json);
	}

}
